//
//  SecondViewController.m
//  MWDateTab
//
//  Created by Jimmy on 1/30/13.
//  Copyright (c) 2013 Jimmy Bouker. All rights reserved.
//

#import "SectionsViewController.h"
#import "AppDelegate.h"


// MACRO VARIABLE 
#define NUMBER_OF_SECTIONS_IN_TABLE_VIEW    3
#define NUMBER_OF_ROWS_IN_SECTION           2

@implementation SectionsViewController
@synthesize sectionsTableView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"Sections", @"Sections");
        self.tabBarItem.image = [UIImage imageNamed:@"second"];
        
        sectionHeaders = [[NSMutableArray alloc] initWithCapacity:NUMBER_OF_SECTIONS_IN_TABLE_VIEW];
        for(int i=0; i<NUMBER_OF_SECTIONS_IN_TABLE_VIEW; i++)
            [sectionHeaders addObject: [NSString stringWithFormat:@"TTS%d",i+1] ];
        
        textForCells = [[NSMutableArray alloc] initWithCapacity:NUMBER_OF_ROWS_IN_SECTION];
        [textForCells addObject:@"Male"];
        [textForCells addObject:@"Female"];
        
    }
    return self;
}
							
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return NUMBER_OF_SECTIONS_IN_TABLE_VIEW;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return NUMBER_OF_ROWS_IN_SECTION;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
    cell.textLabel.text = [textForCells objectAtIndex:indexPath.row];
    
    return cell;
}

-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return [sectionHeaders objectAtIndex:section];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *message = [NSString stringWithFormat:@"%@, %@", [sectionHeaders objectAtIndex:indexPath.section], [tableView cellForRowAtIndexPath:indexPath].textLabel.text];
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Cell hit" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
    [alert release];
}

@end
